package client.controler;

import client.exceptions.NotInitializedException;
import sharedObjects.MessageNotification;
import sharedObjects.ObjectWrapper;

public class PackageController {
	private PackageSender ps;
	private PackageBuilder pb;
	private boolean initialized = false;
	
	
	
	
	
	public boolean isInitialized() {
		return initialized;
	}

	public void setInitialized(boolean initialized) {
		this.initialized = initialized;
	}

	public PackageController(){
		
	}
	
	public void initialize(){
		try{
			ps = new  PackageSender();
			pb = new PackageBuilder();
			initialized = true;
			}
			catch(Exception e){
				e.printStackTrace();
			}
	}
	
        
        
	public void sendField() throws NotInitializedException{
		
		if (initialized == false){
			throw new NotInitializedException("PackageController must be Initialized first");
		}
		
		Object o = pb.getShipstoragePackage();
		try{
		ps.sendPackage(o);
                    ps.sendPackage(new ObjectWrapper(new MessageNotification(MessageNotification.OK), ObjectWrapper.STATUS_MESSAGE));
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
